package com.project.controller;

import com.project.bean.UserBean;
import com.project.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("user")
public class UserController {
    @Autowired
    private IUserService userService;

    @RequestMapping("login")
    public String login(String userName, String pwd, HttpServletRequest req) {
        UserBean user = userService.login(userName, pwd);
        if (user != null) {
            req.getSession().setAttribute("loginUser", user);
            if (user.getGrade().equals("管理员")) {
                return "yes";
            }
            if (user.getGrade().equals("送货员")) {
                return "send";
            }
            return "ok";
        }
        return "no";
    }

    @RequestMapping("getLoginInfo")
    public UserBean getLoginInfo(HttpServletRequest req) {
        UserBean user = (UserBean) req.getSession().getAttribute("loginUser");
        return user;
    }


}
